package pe.edu.upc.dew.pharma.util;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import pe.edu.upc.dew.pharma.model.PedidoDet;
import pe.edu.upc.dew.pharma.service.PedidoService;

public class ServletJSON {
	
	@SuppressWarnings("unused")
	private HttpSession session;
	
	private PedidoService pedidoService;
	
	private static final Log logger = LogFactory.getLog(ServletJSON.class);
	
	public ServletJSON(HttpSession session) {
		if(logger.isInfoEnabled())
		{
			logger.info("Creando ServletJSON");
		}
		this.session = session;
		
		WebApplicationContext applicationContext = ContextLoader.getCurrentWebApplicationContext();
		AutowireCapableBeanFactory autowire = applicationContext.getAutowireCapableBeanFactory();
		
		pedidoService = (PedidoService) autowire.getBean("pedidoService", PedidoService.class);
		
	}
	
	public List<PedidoDet> obtenerDetallePedido(int idPedido)
	{
		return pedidoService.obtenerDetallePedido(idPedido);
	}

	

}
